#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n>m) cout<<n-m<<endl;
	else 
	{
		int ans = 0;
		while(n<m)
		{
			if(m%2)
			{
				ans++;
				m++;
			}
			m = m/2;
			ans++;
		}
		cout<<ans+n-m<<endl;
	}
} 
